package com.heima.test93;

import java.util.Arrays;

/*(1)定义一个方法
    public Object[] deleteSubString(String str1,String str2) {

    }
  (2)方法功能描述:从str1中删除所有的str2,并返回删除后的结果,返回结果为Object[]数组
    * 该数组的第一个元素删除所有的str2后的最终的字符串
    * 该数组的第二个元素为删除的str2的个数
*/
public class Test06 {

    public static void main(String[] args) {
        String s1 = "aabbccaaddssddewwd";
        String s2 = "aa";
        Object[] objects = deleteSubString(s1, s2);
        System.out.println(Arrays.toString(objects));

    }

    public static Object[] deleteSubString(String str1,String str2) {
        Object[] arr = new Object[2];
        int sum = 0;
        while (str1.contains(str2)){
            str1 = str1.replaceFirst(str2,"");
            sum++;
        }
        arr[0] = str1;
        arr[1] = sum;
        return arr;
    }

   /* public static Object[] deleteSubString1(String str1,String str2) {
        Object[] arr = new Object[2];
        int sum = 0;
        while (true){
            int i = str1.indexOf(str2);
            if (i<0){
                break;
            }
            sum++;
            str1 = str1.substring(i,str2.length()+i+1);
        }
        arr[0] = str1;
        arr[1] = sum;
        return arr;
    }*/


}
